<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta content="" name="keywords">

  <title> Django - </title>
  <meta name="description" content="" />
  <meta property="og:title" content="Django" />
  <meta name="twitter:title" content="Django" />
  <meta name="author" content="{Description { .Site.Author.name }}"/>
  <meta name="twitter:card" content="summary" />
  <meta property="og:url" content="https://systemime.github.io/categories/django/" />
  <meta property="og:type" content="website" />
  <meta property="og:site_name" content="听风的小站" />

  <meta name="generator" content="Hugo 0.67.0" />
  <link rel="canonical" href="https://systemime.github.io/categories/django/" />
  <link rel="alternate" href="https://systemime.github.io/index.xml" type="application/rss+xml" title="听风的小站">
  <script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/jquery-1.12.4.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  
  
  <link rel="stylesheet" href="https://systemime.github.io/css/main.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/my.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/pace.css" />
  <link rel="stylesheet" href="https://cdn.plyr.io/3.4.7/plyr.css">
  <link rel="stylesheet" href="https://systemime.github.io/css/lightgallery.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/baguetteBox.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/search.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/reward.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/share.min.css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" />
  <link rel="stylesheet" href="https://systemime.github.io/css/pygment_highlights.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/highlight.min.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/toc.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/lightbox.css" />
  <link rel="stylesheet" href="https://systemime.github.io/live2d/css/live2d.css" />
  
  <link href="https://systemime.github.io/css/video-js.css" rel="stylesheet">


<meta name="baidu-site-verification" content="g8IYR9SNLF" />
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cffe439e37449bb1c07ab26ab56484bb";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

<link rel="stylesheet" href="https://systemime.github.io/css/prism.css" />









<script src="https://systemime.github.io/js/pace.min.js" data-no-instant></script>



<script src="https://systemime.github.io/js/instantclick.min.js" data-no-instant></script>
   <script data-no-instant>
   InstantClick.on('change', function(isInitialLoad) {
     if (isInitialLoad === false) {
       if (typeof MathJax !== 'undefined') 
         MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
       if (typeof prettyPrint !== 'undefined') 
         prettyPrint();
       if (typeof _hmt !== 'undefined')  
         _hmt.push(['_trackPageview', location.pathname + location.search]);
       if (typeof ga !== 'undefined')  
           ga('send', 'pageview', location.pathname + location.search);
     }
   });
   InstantClick.init();
</script>




<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.7.1/gist-embed.min.js"></script>


<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-3925981084585036",
    enable_page_level_ads: true
  });
</script>



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe.min.css" integrity="sha256-sCl5PUOGMLfFYctzDW3MtRib0ctyUvI9Qsmq2wXOeBY=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/default-skin/default-skin.min.css" integrity="sha256-BFeI1V+Vh1Rk37wswuOYn5lsTcaU96hGaI7OUVCLjPc=" crossorigin="anonymous" />



<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

<div class="pswp__bg"></div>

<div class="pswp__scroll-wrap">
    
    <div class="pswp__container">
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
    </div>
    
    <div class="pswp__ui pswp__ui--hidden">
    <div class="pswp__top-bar">
      
      <div class="pswp__counter"></div>
      <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
      <button class="pswp__button pswp__button--share" title="Share"></button>
      <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
      <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
      
      
      <div class="pswp__preloader">
        <div class="pswp__preloader__icn">
          <div class="pswp__preloader__cut">
            <div class="pswp__preloader__donut"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
      <div class="pswp__share-tooltip"></div>
    </div>
    <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
    </button>
    <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
    </button>
    <div class="pswp__caption">
      <div class="pswp__caption__center"></div>
    </div>
    </div>
    </div>
</div>

</head>

  <body>
    <nav class="navbar navbar-default navbar-fixed-top navbar-custom">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="https://systemime.github.io">听风的小站</a>
    </div>
    <div class="collapse navbar-collapse" id="main-navbar">
      <ul class="nav navbar-nav navbar-right">
        
          
            <li>
		    <a title="博客" href="https://systemime.github.io/blog/">博客</a>
              
              
            </li>
          
        
          
            <li>
		    <a title="片刻" href="https://systemime.github.io/moment/">片刻</a>
              
              
            </li>
          
        
          
            <li>
		    <a title="关于" href="https://systemime.github.io/about/">关于</a>
              
              
            </li>
          
        
          
            <li>
		    <a title="留言" href="https://systemime.github.io/message/">留言</a>
              
              
            </li>
          
        

        

        
        
      </ul>
    </div>

    <div class="avatar-container">
      <div class="avatar-img-border">
        
      </div>
    </div>

  </div>
</nav>






    
  <header class="header-section ">
    <div class="intro-header no-img">
      <div class="container">
        <div class="row">
          <div class="col-lg-12 col-md-12 col-md-offset-0">
            <div class="page-heading">
              <h1>#Django</h1>
              <hr class="small">
            </div>
          </div>
        </div>
      </div>
    </div>
  </header>

    
  <div class="container" role="main">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        
        <div class="posts-list">
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-03/djangomodel%E4%B8%AD%E7%9A%84manytomany%E6%B7%BB%E5%8A%A0%E5%88%A0%E9%99%A4%E5%85%B3%E8%81%94%E6%9F%A5%E8%AF%A2/">
                <h2 class="post-title">Django———Model中的ManyToMany添加、删除关联、查询</h2>

                
              </a>

              <p class="post-meta">
                Posted on March 28, 2019
              </p>
              <div class="post-entry">
                
                  <h2 id="先看一段代码">先看一段代码</h2>
<pre><code>class Books(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=128,null=False,unique=True)
    publisher = models.ForeignKey(to=&quot;Publisher&quot;, on_delete=models.CASCADE)

    def __str__(self):
        return &quot;&lt;Book Object: {}&gt;&quot;.format(self.title)

class Author(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=16, null=False, unique=True)
    book = models.ManyToManyField(to=&quot;Books&quot;)
	
    def __str__(self):
        return &quot;&lt;Author Object: {}&gt;&quot;.format(self.name)
</code></pre><p>在这段代码中，建立的表关系如下<img src="https://raw.githubusercontent.com/systemime/my_image/master/models.ManyToManyField%E6%96%B9%E6%B3%95/1.jpg" alt="表关系"></p>
<h2 id="加入有如下模型">加入有如下模型</h2>
<p><strong>models.py</strong></p>
<pre><code>from django.db import models

class person(models.Model):
    name = CharField(max_length=30)

class book(models.Model):
    auther = ManyToManyField(person)
</code></pre><p>假设p为一个person对象，b为一个book对象
则</p>
<pre><code>#添加关联
b.auther.add(p)

#去除关联
b.auther.remove(p)

#返回所有作者
b.auther.all()

#反向查询，返回这个人写的所有书,book即为反向查询的模型名
p.book_set.all()
</code></pre><p>如果在models.py中</p>
<pre><code>from django.db import models

class person(models.Model):
    name = CharField(max_length=30)

class book(models.Model):
    #当关联同一个模型的字段大于一个时，要使用related_name参数来指定表名
    auther = ManyToManyField(person,related_name=&quot;auther&quot;) 
    translater = ManyToManyField(person,related_name=&quot;translater&quot;)
</code></pre><p>此时反向查询p.book_set.all()不可用，取而代之的为</p>
<pre><code>#返回该人写的所有书，book_set被related_name中指定的表名代替
p.auther.all()

#返回该人翻译的所有书
p.translater.all()
</code></pre><p>时间比较晚了，写得比较简洁，仅作为个人笔记</p>

                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/django/">Django</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/model/">Model</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/manytomany/">ManyToMany</a>&nbsp;
                  
                </span>
              

            </article>
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-03/django-%E9%80%9A%E8%BF%87ajax%E6%8F%90%E4%BA%A4%E8%A1%A8%E5%8D%95/">
                <h2 class="post-title">Django —— 通过ajax提交表单</h2>

                
              </a>

              <p class="post-meta">
                Posted on March 20, 2019
              </p>
              <div class="post-entry">
                
                  <h2 id="以博客评论为例说明">以博客评论为例说明</h2>
<p>以对博文的评论为例来讲表单的提交，我们希望达到的结果是：</p>
<ol>
<li>评论完后，可以直接看到自己的评论；</li>
<li>如果评论不正确，比如评论字数超出规定范围，则给出错误提示。</li>
</ol>
<h2 id="传统方案">传统方案</h2>
<p>如果采用传统的提交表单做法，是可以完成的：
** templates **</p>
<pre><code class="language-HTML5" data-lang="HTML5">&lt;form active=&quot;{% url 'blog' blog.id %}&quot; method=&quot;post&quot; class=&quot;comment-form&quot; &gt;
    {% csrf_token %}
  &lt;div class=&quot;form-group&quot;&gt;
    &lt;label class=&quot;name&quot;&gt;名字: &lt;/label&gt;
    &lt;input name=&quot;name&quot; type=&quot;text&quot; class=&quot;#&quot; id=&quot;js-name&quot; placeholder=&quot;请输入用户名&quot;&gt;
    {{ comment_form.name.errors }}
  &lt;/div&gt;
  &lt;div class=&quot;form-group&quot;&gt;
    &lt;label class=&quot;comment&quot;&gt;评论:&lt;/label&gt;
    &lt;textarea name=&quot;content&quot; class=&quot;form-control&quot; id=&quot;js-content&quot; rows=&quot;5&quot; placeholder=&quot;不超过300个字&quot;&gt;&lt;/textarea&gt;
    {{ comment_form.content.errors }}
  &lt;/div&gt;
    &lt;p class=&quot;error company-tips&quot; id=&quot;jsCompanyTips&quot;&gt;&lt;/p&gt;

    &lt;button class=&quot;btn&quot; type=&quot;submit&quot; id=&quot;jsStayBtn&quot; value=&quot;发表&quot;&gt;发表&lt;/button&gt;
&lt;/form&gt;
</code></pre><p><strong>views.py</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="k">class</span> <span class="nc">BlogView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>
    <span class="o">...</span>

    <span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">blog_id</span><span class="p">):</span>
        <span class="n">comment_form</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">comment_form</span><span class="o">.</span><span class="n">is_valid</span><span class="p">():</span>
            <span class="n">comment</span> <span class="o">=</span> <span class="n">comment_form</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">commit</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
            <span class="n">comment</span><span class="o">.</span><span class="n">blog_id</span> <span class="o">=</span> <span class="n">blog_id</span>
            <span class="n">comment</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="n">reverse</span><span class="p">(</span><span class="s1">&#39;blog_id&#39;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">blog_id</span><span class="p">,)))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="o">...</span>
            <span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">&#39;blog-detail.html&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&#34;comment_form&#34;</span><span class="p">:</span> <span class="n">comment_form</span><span class="p">})</span>
</code></pre></div><p>其中CommentForm采用ModelForm的方法，采用这种方法，在else中还得重复写很多传递到前端的代码。</p>
<h2 id="ajax异步传输方案">ajax异步传输方案</h2>
<p>采用ajax异步传输的方式，也就是只针对评论这块的内容，博客中的其它内容并不重新加载（本文中其实还是加载了的）。</p>
<p>形式如下：</p>
<p><strong>template:</strong></p>
<pre><code class="language-HTML5" data-lang="HTML5">&lt;div class=&quot;content-wrap-comment&quot;&gt;

        &lt;h2 class=&quot;comment-add&quot;&gt;发表评论&lt;/h2&gt;

&lt;form  class=&quot;comment-form&quot; id=&quot;jsStayForm&quot;&gt;
    {% csrf_token %}
  &lt;div class=&quot;form-group&quot;&gt;
    &lt;label class=&quot;name&quot;&gt;名字:  &lt;/label&gt;
    &lt;input name=&quot;name&quot; type=&quot;text&quot; class=&quot;#&quot; id=&quot;js-name&quot; placeholder=&quot;   请输入用户名&quot;&gt;
    {{ comment_form.name.errors }}
  &lt;/div&gt;
  &lt;div class=&quot;form-group&quot;&gt;
    &lt;label class=&quot;comment&quot;&gt;评论:&lt;/label&gt;
    &lt;textarea name=&quot;content&quot; class=&quot;form-control&quot; id=&quot;js-content&quot; rows=&quot;5&quot; placeholder=&quot;不超过300个字&quot;&gt;&lt;/textarea&gt;
    {{ comment_form.content.errors }}
  &lt;/div&gt;
    &lt;p class=&quot;error company-tips&quot; id=&quot;jsCompanyTips&quot;&gt;&lt;/p&gt;

    &lt;button class=&quot;btn&quot; type=&quot;button&quot; id=&quot;jsStayBtn&quot; value=&quot;发表&quot;&gt;发表&lt;/button&gt;
&lt;/form&gt;
</code></pre><p><strong>js代码</strong></p>
<pre><code>&lt;script&gt;
    $(function(){
        $('#jsStayBtn').on('click', function(){
            var name = $(&quot;#js-name&quot;).val()
            var content = $(&quot;#js-content&quot;).val()

            $.ajax({
                cache: false,
                type: &quot;POST&quot;,
                url:&quot;/add_comment/&quot;,
                data:{'name': name, 'content': content, 'blog': {{ blog.id }}},
                dateType:&quot;json&quot;,
                async: true,
                beforeSend:function(xhr, settings){
                xhr.setRequestHeader(&quot;X-CSRFToken&quot;, &quot;{{ csrf_token }}&quot;);
            },
                success: function(data) {
                    if(data.status == 'success'){
                        alert(&quot;提交成功&quot;);
                         window.location.reload();//刷新当前页面.
                    }else if(data.status == 'fail'){
{#                        $('#jsCompanyTips').html(data.msg)#}
                        alert(&quot;评论错误，请重新评论&quot;);
                    }
                },
            });
        });
    })

&lt;/script&gt;
</code></pre><p><strong>view.py:</strong></p>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="k">class</span> <span class="nc">AddCommentView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>
    <span class="s2">&#34;&#34;&#34;
</span><span class="s2">    添加评论
</span><span class="s2">    &#34;&#34;&#34;</span>
    <span class="k">def</span> <span class="nf">post</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">):</span>
        <span class="n">comment_form</span> <span class="o">=</span> <span class="n">CommentForm</span><span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">comment_form</span><span class="o">.</span><span class="n">is_valid</span><span class="p">():</span>
            <span class="n">comment</span> <span class="o">=</span> <span class="n">comment_form</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">commit</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
            <span class="n">comment</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s1">&#39;{&#34;status&#34;:&#34;success&#34;}&#39;</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;application/json&#39;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">HttpResponse</span><span class="p">(</span><span class="s1">&#39;{&#34;status&#34;:&#34;fail&#34;, &#34;msg&#34;:&#34;评论错误，请重新评论&#34;}&#39;</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;application/json&#39;</span><span class="p">)</span>
</code></pre></div><p><strong>url.py</strong></p>
<pre><code>url(r'^add_comment/$', AddCommentView.as_view(), name='add_comment'),
</code></pre><p>这里直接将评论的外键blog，也传递到了前端，因此并不用在url中体现了。这也是通过ajax异步传输的好处。</p>
<p>当然，还可以通过json.dump的方法，将form表单中的错误信息传递到前端。</p>
<p>后期学会了将会更新</p>
<h2 id="总结">总结</h2>
<p>采用ajax需要注意的是：</p>
<ol>
<li>form表单中省去active和method，都在ajax中书写；</li>
<li>提交按钮出的，要将submit改为button， 因为我们表单中书写的内容并不通过表单提交，而是通过ajax提交；</li>
<li>前后端数据交换通过json的方式进行。</li>
</ol>
<p>转自：<a href="https://blog.csdn.net/geerniya/article/details/79164505">django学习——通过ajax提交表单</a></p>
<p>大佬博客：<a href="https://thief.one/2017/09/14/3/">nMask&rsquo;s Blog
</a></p>
<p>新的自学网站：<a href="https://code.ziqiangxuetang.com/django/django-ajax.html">自强学堂</a></p>

                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/django/">Django</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/ajax/">ajax</a>&nbsp;
                  
                </span>
              

            </article>
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-03/django%E7%AE%A1%E7%90%86%E5%91%98%E5%AF%86%E7%A0%81%E6%88%96%E7%94%A8%E6%88%B7%E5%90%8D%E5%BF%98%E8%AE%B0%E6%80%8E%E4%B9%88%E5%8A%9E/">
                <h2 class="post-title">Django管理员密码或用户名忘记怎么办</h2>

                
              </a>

              <p class="post-meta">
                Posted on March 16, 2019
              </p>
              <div class="post-entry">
                
                  <h2 id="密码忘了">密码忘了</h2>
<h3 id="进入项目文件">进入项目文件</h3>
<pre><code># 运行下面代码
python manage.py shell
</code></pre><h3 id="修改">修改</h3>
<p>现在你能看到一个类似python的交互界面的终端，输入以下代码，一行一回车</p>
<pre><code>from django.contrib.auth.models import User
user = User.object.get(username='your_account')
user.set_password('你的新密码')
user.save()
quit()
</code></pre><h2 id="用户名忘了">用户名忘了</h2>
<pre><code>&gt;&gt;&gt; from django.contrib.auth.models import User
&gt;&gt;&gt; user = User.object.get(pk=1)
&gt;&gt;&gt; user
&lt;User: you_account&gt;   # 写你的新用户名
&gt;&gt;&gt; user.set_password('写你的新密码')
&gt;&gt;&gt; user.save()
&gt;&gt;&gt; quit()
</code></pre>
                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/django/">Django</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/%E6%89%BE%E5%9B%9E%E5%AF%86%E7%A0%81/">找回密码</a>&nbsp;
                  
                </span>
              

            </article>
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-01/django%E5%88%9B%E5%BB%BA%E8%B6%85%E7%BA%A7%E7%94%A8%E6%88%B7/">
                <h2 class="post-title">Django创建超级用户</h2>

                
              </a>

              <p class="post-meta">
                Posted on January 27, 2019
              </p>
              <div class="post-entry">
                
                  <h2 id="运行命令">运行命令</h2>
<blockquote>
<p>python manage.py createsuperuser</p>
</blockquote>
<h4 id="输入用户名">输入用户名</h4>
<blockquote>
<p>Username (leave blank to use &lsquo;administrator&rsquo;): user01  # 换成你的想要的</p>
</blockquote>
<h4 id="输入email">输入email：</h4>
<blockquote>
<p>Email address: (在这里输入你的自己的邮箱帐号)</p>
</blockquote>
                  <a href="https://systemime.github.io/blog/2019-01/django%E5%88%9B%E5%BB%BA%E8%B6%85%E7%BA%A7%E7%94%A8%E6%88%B7/" class="post-read-more">[Read More]</a>
                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/admin/">admin</a>&nbsp;
                  
                </span>
              

            </article>
          
        </div>
        
          <ul class="pager main-pager">
            
              <li class="previous">
                <a href="https://systemime.github.io/categories/django/page/2">&larr; Newer Posts</a>
              </li>
            
            
          </ul>
        
      </div>
    <div align="center" class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        

<ul class="pagination">
    
    <li class="page-item">
        <a href="https://systemime.github.io/categories/django/" class="page-link" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
    </li>
    
    <li class="page-item">
    <a href="https://systemime.github.io/categories/django/page/2/" class="page-link" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
    </li>
    
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/categories/django/">1</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/categories/django/page/2/">2</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item active"><a class="page-link" href="https://systemime.github.io/categories/django/page/3/">3</a></li>
    
    
    <li class="page-item disabled">
    <a  class="page-link" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
    </li>
    
    <li class="page-item">
        <a href="https://systemime.github.io/categories/django/page/3/" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
    </li>
    
</ul>


        
        
        
        
        
      </div>
    </div>
  </div>

    <div class="rocket"><img src="https://systemime.github.io/img/rocket_up.png" alt="" width="100" height="100"></div>
<script>
    $(function () {
      $(window).scroll(function () {
        
        if ($(window).scrollTop() >= 1000) {
          $('.rocket').stop().fadeIn(1000);
        }else {
          $('.rocket').stop().fadeOut(1000);
        }
      })
      
      $('.rocket').click(function () {
        $('html,body').stop().animate({scrollTop:0},400);
       
      })
    })

</script>

    
    <div id="landlord">
        <div class="message" style="opacity:0"></div>
        <canvas id="live2d" width="280" height="250" class="live2d"></canvas>
        <div class="hide-button">隐藏</div>
    </div>
    
    <footer id="copyright">
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <ul class="list-inline text-center footer-links">
          
          
        </ul>
        <p class="credits copyright text-muted">
        &copy;2017-2018
          
          &nbsp;&bull;&nbsp;
          September 20,2019
          updated
          
            &nbsp;&bull;&nbsp;
            <a href="https://systemime.github.io">Home</a>
          
        </p>

        <p class="credits theme-by text-muted">
        <a href="https://servicemesher.github.io" target="_blank">ServiceMesher</a>&nbsp;&bull;&nbsp;<a href="https://github.com/yangchuansheng/k8s-knowledge" target="_blank">Kubernetes 知识图谱</a>
        <br />
        <span id="busuanzi_container_site_pv">
            本站已被访问 <span id="busuanzi_value_site_pv"></span> 次啦
        </span>
        <span id="busuanzi_container_site_uv">
            &ensp;|&ensp;&thinsp;您是第 <span id="busuanzi_value_site_uv"></span> 位到访的小伙伴喔
        </span>
        </p>
        
        <p class="credits theme-by text-muted">
          <a href="http://gohugo.io">Hugo v0.67.0</a> powered &nbsp;&bull;&nbsp; Theme by <a href="http://deanattali.com/beautiful-jekyll/">Beautiful Jekyll</a> adapted to <a href="https://github.com/halogenica/beautifulhugo">Beautiful Hugo</a>
          
          <center><section class="credits theme-by text-muted">
    <span class="footer__copyright">
    <div>
    <span id="span_dt_dt"> </span>
    <script language="javascript">
      function show_date_time(){
        window.setTimeout("show_date_time()", 1000);
        BirthDay=new Date("7/8/2017 10:56:12");
        today=new Date();
        timeold=(today.getTime()-BirthDay.getTime());
        sectimeold=timeold/1000
        secondsold=Math.floor(sectimeold);
        msPerDay=24*60*60*1000
        e_daysold=timeold/msPerDay
        daysold=Math.floor(e_daysold);
        e_hrsold=(e_daysold-daysold)*24;
        hrsold=Math.floor(e_hrsold);
        e_minsold=(e_hrsold-hrsold)*60;
        minsold=Math.floor((e_hrsold-hrsold)*60);
        seconds=Math.floor((e_minsold-minsold)*60);
        span_dt_dt.innerHTML="本博客已经开心运行 "+daysold+" 天 "+hrsold+" 小时 "+minsold+" 分 "+seconds+" 秒";
      }
      show_date_time();
    </script>
    </div>
</script>
</section>
</center>
        </p>
      </div>
    </div>
  </div>
</footer>


<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/bootstrap.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/photoswipe-ui-default.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/photoswipe.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/auto-render.min.js"></script>
<script src="https://systemime.github.io/js/main.js"></script>
<script src="https://systemime.github.io/js/clipboard.min.js"></script>
<script src="https://systemime.github.io/js/prism.js?t=123"></script>
<script src="https://systemime.github.io/js/highlight.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/katex.min.js"></script>
<script src="https://systemime.github.io/js/reward.js"></script>
<script src="https://systemime.github.io/js/canvas_ribbon.js"></script>
<script> renderMathInElement(document.body); </script>

<script src="https://systemime.github.io/js/baguetteBox.js"></script>
<script> baguetteBox.run('.gallery');</script>






<script async defer src="https://buttons.github.io/buttons.js"></script>


<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
<script type="text/javascript" src="https://systemime.github.io/js/quicklink.umd.js"></script>
<script>
window.addEventListener('load', () =>{
   quicklink();
});
</script>



<script type="text/javascript">
 
var a_idx = 0;
jQuery(document).ready(function($) {
    $("body").click(function(e) {
        var a = new Array("Docker", "Kubernetes", "Prometheus", "Envoy", "Istio", "Service Mesh", "Cloud Native");
        var $i = $("<span />").text(a[a_idx]);
        a_idx = (a_idx + 1) % a.length;
        var x = e.pageX,
        y = e.pageY;
        function randomColor() {
          var flakeColor = new Array("#FFDA65", "#00BFFF", "#BA55D3", "#FFA07A", "#87CEEB", "#FFB6C1");
          var snowColor = flakeColor[Math.floor(flakeColor.length * Math.random())];
          return snowColor;
        }
        $i.css({
            "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
            "top": y - 20,
            "left": x,
            "position": "absolute",
            "font-weight": "bold",
            "color": randomColor()
        });
        $("body").append($i);
        $i.animate({
            "top": y - 180,
            "opacity": 0
        },
        1500,
        function() {
            $i.remove();
        });
    });
});
</script>


<script type="text/javascript" src="https://systemime.github.io/js/lightbox.js"></script>











<script src="https://cdn.plyr.io/3.4.7/plyr.js"></script>
<script>const player = new Plyr('#player');</script>


<script async defer src="https://buttons.github.io/buttons.js"></script>


  </body>
</html>

